#pragma once

#include <xtd/tree2d.h>

namespace outline {

/// the class stores four types of segments, constituting a bound of a raster mask:
///	vertical segments with normal to the left and to the right,
/// horizontal segments with normal to the up and to the down
/// T is some integer type
template <typename T>
class segmap
{
public:
	typedef size_t size_type;
	typedef T elem_type;
	typedef point<T> point_type;
	typedef rect<T> rect_type;
public:
	template <typename I>
	segmap(I first, I last);
public:
	void search_half_window(size_type h);
	size_type search_half_window() const;
public:
	///searchs the nearest point on the segment, having normal in the same sirection as given one;
	///if no such segment is found in the search window, than pos is returned
	template <typename U> //U is some real type
	point<U> nearest(point<U> const & pos, point<U> const & norm) const;
private:
	typedef xtd::tree2d<point_type, point_type, rect_type> tree_type;
	typedef typename tree_type::range_iterator range_iterator;
private:
	tree_type vl, vr; ///< vertical segments with normal to the left and to the right
	tree_type hu, hd; ///< horizontal segments with normal to the up and to the down
	size_type shw; ///< search half-window
};

} //namespace outline
